package com.example.wzdjcrdpassword.repository;

import com.example.wzdjcrdpassword.entity.SystemEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface SystemRepository extends JpaRepository<SystemEntity, Long> {
    
    Optional<SystemEntity> findByBusinessIdAndIsDeleted(String businessId, String isDeleted);
    
    Optional<SystemEntity> findBySystemIdAndIsDeleted(String systemId, String isDeleted);
    
    List<SystemEntity> findBySystemTypeAndIsDeleted(String systemType, String isDeleted);
    
    List<SystemEntity> findBySystemNameContainingAndIsDeleted(String systemName, String isDeleted);
    
    @Query("SELECT s FROM SystemEntity s WHERE s.isDeleted = 'NO'")
    List<SystemEntity> findAllActiveSystems();
    
    @Query("SELECT s FROM SystemEntity s WHERE s.systemType = :systemType AND s.systemId = :systemId AND s.isDeleted = 'NO'")
    Optional<SystemEntity> findBySystemTypeAndSystemId(@Param("systemType") String systemType, 
                                                     @Param("systemId") String systemId);
}